package com.niit.conteoller;

import com.niit.pojo.Typing;
import com.niit.pojo.User;
import com.niit.service.GoodService;
import com.niit.service.TypeService;
import com.niit.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;



//前台，用户
//登陆注册
@Controller
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public String login(){
        return "login";
    }
    @RequestMapping("/index")
    public String index(User user){
        //调用登陆
        User user1=userService.Login(user);
        if (user1!=null){
            if(user1.getRole()==1){
                return "index";//管理员
            }else {
                return "index1";//用户
            }
        }else{
            return "login";
        }
    }
//调用注册
    @RequestMapping("/register")
    public String register(){
        return "register";
    }
    @RequestMapping("/get")

    public String Register(User user){
        int i=userService.Register(user);
        if(i>0)
            return "redirect:login";
        else
            return "注册失败";
    }


    @GetMapping("/get")
@ResponseBody
public String selecttype(Typing typing ){
        return typing.toString();
        //http://localhost:8080/get?t_name=tom&t_id=123
};





}
